From ee5e24ff8b5ca2933534f3a6b954964fb547cec5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 5 Feb 2015 23:27:53 -0800 Subject: [PATCH] Update to rust master --- Cargo.lock | 65 ++++++++++---------- src/bin/bench.rs | 2 +- src/bin/cargo.rs | 51 +++++++--------- src/bin/run.rs | 2 +- src/bin/test.rs | 2 +- src/cargo/lib.rs | 23 ++++---- src/cargo/ops/cargo_new.rs | 8 +-- src/cargo/ops/cargo_package.rs | 4 +- src/cargo/ops/cargo_run.rs | 5 +- src/cargo/ops/cargo_rustc/compilation.rs | 2 +- src/cargo/ops/cargo_rustc/engine.rs | 10 ++-- src/cargo/ops/cargo_rustc/mod.rs | 5 +- src/cargo/ops/cargo_test.rs | 3 +- src/cargo/ops/registry.rs | 10 ++-- src/cargo/util/config.rs | 14 +++-- src/cargo/util/errors.rs | 14 +++-- src/cargo/util/important_paths.rs | 34 +++++------ src/cargo/util/paths.rs | 10 +++- src/cargo/util/process_builder.rs | 6 +- src/cargo/util/profile.rs | 6 +- src/cargo/util/toml.rs | 3 +- src/rustversion.txt | 2 +- tests/support/mod.rs | 15 ++--- tests/support/paths.rs | 6 +- tests/test_cargo.rs | 16 ++--- tests/test_cargo_bench.rs | 6 +- tests/test_cargo_build_lib.rs | 4 +- tests/test_cargo_compile.rs | 42 ++++++------- tests/test_cargo_compile_custom_build.rs | 75 ++++++++++++------------ tests/test_cargo_compile_plugins.rs | 10 ++-- tests/test_cargo_cross_compile.rs | 54 ++++++++--------- tests/test_cargo_new.rs | 20 +++---- tests/test_cargo_profiles.rs | 6 +- tests/test_cargo_run.rs | 18 +++--- tests/test_cargo_test.rs | 4 +- tests/tests.rs | 2 +- 36 files changed, 284 insertions(+), 275 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0248908a7..e9034f5f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,33 +2,33 @@ name = "cargo" version = "0.1.0" dependencies = [ - "advapi32-sys 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "docopt 0.6.34 (registry+https://github.com/rust-lang/crates.io-index)", + "advapi32-sys 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curl 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "docopt 0.6.35 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git)", "log 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "registry 0.1.0", - "rustc-serialize 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "url 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "advapi32-sys" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -38,13 +38,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "curl" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "curl-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "url 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -60,11 +60,11 @@ dependencies = [ [[package]] name = "docopt" -version = "0.6.34" +version = "0.6.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "regex 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -78,11 +78,11 @@ dependencies = [ [[package]] name = "flate2" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -92,17 +92,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "git2" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "url 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "url 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "glob" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -115,7 +115,7 @@ name = "kernel32-sys" version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -125,7 +125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libssh2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -172,10 +172,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "miniz-sys" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -206,13 +207,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "registry" version = "0.1.0" dependencies = [ - "curl 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "curl 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-serialize" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -232,7 +233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -249,20 +250,20 @@ name = "toml" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rustc-serialize 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "url" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/src/bin/bench.rs b/src/bin/bench.rs index d057c3626..99fa48eb0 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -77,7 +77,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { None => Ok(None), Some(err) => { Err(match err.exit { - Some(ExitStatus(i)) => CliError::new("", i as u32), + Some(ExitStatus(i)) => CliError::new("", i as i32), _ => CliError::from_boxed(box Human(err), 101) }) } diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 60b0b9b47..95ebc1c2b 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -1,15 +1,15 @@ -#![feature(collections, core, io, os, path)] +#![feature(collections, core, io, path, env)] extern crate "rustc-serialize" as rustc_serialize; extern crate cargo; -#[macro_use] extern crate log; extern crate env_logger; +#[macro_use] extern crate log; use std::collections::BTreeSet; -use std::os; -use std::old_io; +use std::env; use std::old_io::fs::{self, PathExtensions}; use std::old_io::process::{Command,InheritFd,ExitStatus,ExitSignal}; +use std::old_io; use cargo::{execute_main_without_stdin, handle_error, shell}; use cargo::core::MultiShell; @@ -86,7 +86,6 @@ macro_rules! each_subcommand{ ($mac:ident) => ({ on this top-level information. */ fn execute(flags: Flags, config: &Config) -> CliResult> { - debug!("executing; cmd=cargo; args={:?}", os::args()); config.shell().set_verbose(flags.flag_verbose); if flags.flag_list { @@ -100,7 +99,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult> { let (mut args, command) = match flags.arg_command.as_slice() { "" | "help" if flags.arg_args.len() == 0 => { config.shell().set_verbose(true); - let args = &[os::args()[0].clone(), "-h".to_string()]; + let args = &["foo".to_string(), "-h".to_string()]; let r = cargo::call_main_without_stdin(execute, config, USAGE, args, false); cargo::process_executed(r, &mut **config.shell()); @@ -113,7 +112,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult> { s => (flags.arg_args.clone(), s), }; args.insert(0, command.to_string()); - args.insert(0, os::args()[0].clone()); + args.insert(0, "foo".to_string()); macro_rules! cmd{ ($name:ident) => ( if command.as_slice() == stringify!($name).replace("_", "-").as_slice() { @@ -136,8 +135,9 @@ fn execute(flags: Flags, config: &Config) -> CliResult> { fn find_closest(cmd: &str) -> Option { match list_commands().iter() - // doing it this way (instead of just .min_by(|c| c.lev_distance(cmd))) - // allows us to only make suggestions that have an edit distance of + // doing it this way (instead of just .min_by(|c| + // c.lev_distance(cmd))) allows us to only make + // suggestions that have an edit distance of // 3 or less .map(|c| (lev_distance(c.as_slice(), cmd), c)) .filter(|&(d, _): &(usize, &String)| d < 4) @@ -171,11 +171,11 @@ fn execute_subcommand(cmd: &str, args: &[String], shell: &mut MultiShell) { match status { Ok(ExitStatus(0)) => (), Ok(ExitStatus(i)) => { - handle_error(CliError::new("", i as u32), shell) + handle_error(CliError::new("", i as i32), shell) } Ok(ExitSignal(i)) => { let msg = format!("subcommand failed with signal: {}", i); - handle_error(CliError::new(msg, i as u32), shell) + handle_error(CliError::new(msg, i as i32), shell) } Err(old_io::IoError{kind, ..}) if kind == old_io::FileNotFound => handle_error(CliError::new("No such subcommand", 127), shell), @@ -202,11 +202,11 @@ fn list_commands() -> BTreeSet { _ => continue }; if filename.starts_with(command_prefix) && - filename.ends_with(os::consts::EXE_SUFFIX) && + filename.ends_with(env::consts::EXE_SUFFIX) && is_executable(entry) { let command = &filename[ command_prefix.len().. - filename.len() - os::consts::EXE_SUFFIX.len()]; + filename.len() - env::consts::EXE_SUFFIX.len()]; commands.insert(String::from_str(command)); } } @@ -229,7 +229,7 @@ fn is_executable(path: &Path) -> bool { /// Get `Command` to run given command. fn find_command(cmd: &str) -> Option { - let command_exe = format!("cargo-{}{}", cmd, os::consts::EXE_SUFFIX); + let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX); let dirs = list_command_directory(); let mut command_paths = dirs.iter().map(|dir| dir.join(command_exe.as_slice())); command_paths.find(|path| path.exists()) @@ -238,20 +238,13 @@ fn find_command(cmd: &str) -> Option { /// List candidate locations where subcommands might be installed. fn list_command_directory() -> Vec { let mut dirs = vec![]; - match os::self_exe_path() { - Some(path) => { - dirs.push(path.join("../lib/cargo")); - dirs.push(path); - }, - None => {} - }; - match std::os::getenv("PATH") { - Some(val) => { - for dir in os::split_paths(val).iter() { - dirs.push(Path::new(dir)) - } - }, - None => {} - }; + if let Ok(mut path) = env::current_exe() { + path.pop(); + dirs.push(path.join("../lib/cargo")); + dirs.push(path); + } + if let Some(val) = env::var("PATH") { + dirs.extend(env::split_paths(&val)); + } dirs } diff --git a/src/bin/run.rs b/src/bin/run.rs index 272c1c830..da295a4cc 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -87,7 +87,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { None => Ok(None), Some(err) => { Err(match err.exit { - Some(ExitStatus(i)) => CliError::from_boxed(box err, i as u32), + Some(ExitStatus(i)) => CliError::from_boxed(box err, i as i32), _ => CliError::from_boxed(box err, 101), }) } diff --git a/src/bin/test.rs b/src/bin/test.rs index 3d39d7f8f..1e27d4465 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -79,7 +79,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { None => Ok(None), Some(err) => { Err(match err.exit { - Some(ExitStatus(i)) => CliError::new("", i as u32), + Some(ExitStatus(i)) => CliError::new("", i as i32), _ => CliError::from_boxed(box Human(err), 101) }) } diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 28b2696ae..9e2e0f85f 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -1,5 +1,5 @@ #![deny(unused)] -#![feature(collections, core, hash, io, libc, os, path, std_misc, unicode)] +#![feature(collections, hash, io, libc, os, path, std_misc, unicode, env, core)] #![cfg_attr(test, deny(warnings))] extern crate libc; @@ -22,10 +22,10 @@ extern crate url; extern crate registry; +use std::env; use std::error::Error; use std::old_io::stdio::{stdout_raw, stderr_raw}; use std::old_io::{self, stdout, stderr}; -use std::os; use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::json::{self, Json}; use docopt::Docopt; @@ -33,7 +33,7 @@ use docopt::Docopt; use core::{Shell, MultiShell, ShellConfig}; use term::color::{BLACK, RED}; -pub use util::{CargoError, CliError, CliResult, human, Config}; +pub use util::{CargoError, CliError, CliResult, human, Config, ChainError}; pub mod core; pub mod ops; @@ -93,12 +93,15 @@ fn process(mut callback: F) V: Encodable { let mut shell = shell(true); - process_executed({ - match Config::new(&mut shell) { - Ok(cfg) => callback(os::args().as_slice(), &cfg), - Err(e) => Err(CliError::from_boxed(e, 101)), - } - }, &mut shell) + process_executed((|| { + let config = try!(Config::new(&mut shell)); + let args: Vec<_> = try!(env::args().map(|s| { + s.into_string().map_err(|s| { + human(format!("invalid unicode in argument: {:?}", s)) + }) + }).collect()); + callback(&args, &config) + })(), &mut shell) } pub fn process_executed(result: CliResult>, shell: &mut MultiShell) @@ -158,7 +161,7 @@ pub fn handle_error(err: CliError, shell: &mut MultiShell) { with --verbose.".to_string(), BLACK); } - std::os::set_exit_status(exit_code as isize); + std::env::set_exit_status(exit_code); } fn handle_cause(mut cargo_err: &CargoError, shell: &mut MultiShell) -> bool { diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 85ab012c7..a2bafbc34 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -1,6 +1,6 @@ -use std::os; -use std::old_io::{self, fs, File}; +use std::env; use std::old_io::fs::PathExtensions; +use std::old_io::{self, fs, File}; use rustc_serialize::{Decodable, Decoder}; @@ -134,8 +134,8 @@ fn discover_author() -> CargoResult<(String, Option)> { let git_config = git_config.as_ref(); let name = git_config.and_then(|g| g.get_str("user.name").ok()) .map(|s| s.to_string()) - .or_else(|| os::getenv("USER")) // unix - .or_else(|| os::getenv("USERNAME")); // windows + .or_else(|| env::var_string("USER").ok()) // unix + .or_else(|| env::var_string("USERNAME").ok()); // windows let name = match name { Some(name) => name, None => { diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 1a75d9c2d..07d83e038 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -1,6 +1,6 @@ use std::old_io::{fs, File, USER_DIR}; use std::old_io::fs::PathExtensions; -use std::path; +use std::old_path; use tar::Archive; use flate2::{GzBuilder, BestCompression}; @@ -133,7 +133,7 @@ fn tar(pkg: &Package, src: &PathSource, config: &Config, shell.status("Archiving", relative.as_slice()) })); let path = format!("{}-{}{}{}", pkg.get_name(), - pkg.get_version(), path::SEP, relative); + pkg.get_version(), old_path::SEP, relative); try!(ar.append(path.as_slice(), &mut file).chain_error(|| { internal(format!("could not archive source file `{}`", relative)) })); diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 0ef3986a9..883b7f0a4 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -1,4 +1,3 @@ -use std::os; use ops::{self, ExecEngine}; use util::{CargoResult, human, process, ProcessError, ChainError}; @@ -48,14 +47,14 @@ pub fn run(manifest_path: &Path, (None, true) => dst.join("examples").join(bin.get_name()), (None, false) => dst.join(bin.get_name()), }; - let exe = match exe.path_relative_from(&try!(os::getcwd())) { + let exe = match exe.path_relative_from(config.cwd()) { Some(path) => path, None => exe, }; let process = try!(try!(compile.target_process(exe, &root)) .into_process_builder()) .args(args) - .cwd(try!(os::getcwd())); + .cwd(config.cwd().clone()); try!(config.shell().status("Running", process.to_string())); Ok(process.exec().err()) diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index 5750924c2..3a220cfc4 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::dynamic_lib::DynamicLibrary; use std::ffi::CString; -use std::path::BytesContainer; +use std::old_path::BytesContainer; use semver::Version; use core::{PackageId, Package}; diff --git a/src/cargo/ops/cargo_rustc/engine.rs b/src/cargo/ops/cargo_rustc/engine.rs index e3ca33a64..9998e0e7b 100644 --- a/src/cargo/ops/cargo_rustc/engine.rs +++ b/src/cargo/ops/cargo_rustc/engine.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; +use std::env; use std::ffi::CString; use std::fmt::{self, Formatter}; use std::old_io::process::ProcessOutput; -use std::os; -use std::path::BytesContainer; +use std::old_path::BytesContainer; use util::{self, CargoResult, ProcessError, ProcessBuilder}; @@ -39,13 +39,11 @@ pub struct CommandPrototype { impl CommandPrototype { pub fn new(ty: CommandType) -> CargoResult { - use std::os; - Ok(CommandPrototype { ty: ty, args: Vec::new(), env: HashMap::new(), - cwd: try!(os::getcwd()), + cwd: try!(env::current_dir()), }) } @@ -87,7 +85,7 @@ impl CommandPrototype { pub fn get_env(&self, var: &str) -> Option { self.env.get(var).cloned().or_else(|| { - Some(os::getenv(var).map(|s| CString::from_vec(s.into_bytes()))) + Some(env::var_string(var).ok().map(|s| CString::from_vec(s.into_bytes()))) }).and_then(|val| val) } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 0e81545b7..e10363ddb 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -3,7 +3,7 @@ use std::dynamic_lib::DynamicLibrary; use std::ffi::CString; use std::old_io::fs::{self, PathExtensions}; use std::os; -use std::path; +use std::old_path; use std::sync::Arc; use core::{SourceMap, Package, PackageId, PackageSet, Target, Resolve}; @@ -455,6 +455,7 @@ fn crawl_build_deps<'a>(cx: &'a Context, pkg: &'a Package, // For all plugin dependencies, add their -L paths (now calculated and // present in `state`) to the dynamic library load path for the command to // execute. +#[allow(deprecated)] // need an OsStr based Command fn add_plugin_deps(rustc: CommandPrototype, build_state: &BuildMap, plugin_deps: Vec) @@ -726,7 +727,7 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package v.push_all(target.get_name().as_bytes()); v.push(b'='); v.push_all(layout.root().as_vec()); - v.push(path::SEP_BYTE); + v.push(old_path::SEP_BYTE); v.push_all(filename.as_bytes()); cmd = cmd.arg("--extern").arg(v.as_slice()); } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 2355d13bd..6560d5503 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,4 +1,3 @@ -use std::os; use core::Source; use sources::PathSource; @@ -28,7 +27,7 @@ pub fn run_tests(manifest_path: &Path, target_name.map_or(true, |target_name| target_name == test_name.as_slice()) }); - let cwd = try!(os::getcwd()); + let cwd = config.cwd(); for &(_, ref exe) in tests_to_run { let to_display = match exe.path_relative_from(&cwd) { Some(path) => path, diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 60f2f9202..a338eaabf 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; +use std::env; +use std::iter::repeat; use std::old_io::File; use std::old_io::fs::PathExtensions; -use std::iter::repeat; -use std::os; use curl::http; use git2; @@ -191,7 +191,7 @@ pub fn http_proxy(config: &Config) -> CargoResult> { } Err(..) => {} } - Ok(os::getenv("HTTP_PROXY")) + Ok(env::var_string("HTTP_PROXY").ok()) } pub fn http_timeout(config: &Config) -> CargoResult> { @@ -199,13 +199,13 @@ pub fn http_timeout(config: &Config) -> CargoResult> { Some((s, _)) => return Ok(Some(s)), None => {} } - Ok(os::getenv("HTTP_TIMEOUT").and_then(|s| s.parse().ok())) + Ok(env::var_string("HTTP_TIMEOUT").ok().and_then(|s| s.parse().ok())) } pub fn registry_login(config: &Config, token: String) -> CargoResult<()> { let RegistryConfig { index, token: _ } = try!(registry_configuration(config)); let mut map = HashMap::new(); - let p = try!(os::getcwd()); + let p = config.cwd().clone(); match index { Some(index) => { map.insert("index".to_string(), ConfigValue::String(index, p.clone())); diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 5f5800140..dba02d565 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -1,9 +1,11 @@ -use std::{fmt, os, mem}; use std::cell::{RefCell, RefMut, Ref, Cell}; -use std::collections::hash_map::{HashMap}; use std::collections::hash_map::Entry::{Occupied, Vacant}; -use std::old_io; +use std::collections::hash_map::{HashMap}; +use std::env; +use std::fmt; +use std::mem; use std::old_io::fs::{self, PathExtensions, File}; +use std::old_io; use rustc_serialize::{Encodable,Encoder}; use toml; @@ -28,7 +30,7 @@ pub struct Config<'a> { impl<'a> Config<'a> { pub fn new(shell: &'a mut MultiShell) -> CargoResult> { - let cwd = try!(os::getcwd().chain_error(|| { + let cwd = try!(env::current_dir().chain_error(|| { human("couldn't get the current directory of the process") })); let (rustc_version, rustc_host) = try!(ops::rustc_version()); @@ -383,8 +385,8 @@ impl ConfigValue { } fn homedir() -> Option { - let cargo_home = os::getenv("CARGO_HOME").map(|p| Path::new(p)); - let user_home = os::homedir().map(|p| p.join(".cargo")); + let cargo_home = env::var_string("CARGO_HOME").map(|p| Path::new(p)).ok(); + let user_home = env::home_dir().map(|p| p.join(".cargo")); return cargo_home.or(user_home); } diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index 0a528f9ed..ff5c0add9 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -193,7 +193,7 @@ pub type CliResult = Result; pub struct CliError { pub error: Box, pub unknown: bool, - pub exit_code: u32 + pub exit_code: i32 } impl Error for CliError { @@ -208,22 +208,28 @@ impl fmt::Display for CliError { } impl CliError { - pub fn new(error: S, code: u32) -> CliError { + pub fn new(error: S, code: i32) -> CliError { let error = human(error.as_slice().to_string()); CliError::from_boxed(error, code) } - pub fn from_error(error: E, code: u32) -> CliError { + pub fn from_error(error: E, code: i32) -> CliError { let error = Box::new(error) as Box; CliError::from_boxed(error, code) } - pub fn from_boxed(error: Box, code: u32) -> CliError { + pub fn from_boxed(error: Box, code: i32) -> CliError { let human = error.is_human(); CliError { error: error, exit_code: code, unknown: !human } } } +impl FromError> for CliError { + fn from_error(err: Box) -> CliError { + CliError::from_boxed(err, 101) + } +} + // ============================================================================= // various impls diff --git a/src/cargo/util/important_paths.rs b/src/cargo/util/important_paths.rs index 4ba23b36f..7cc74d9d5 100644 --- a/src/cargo/util/important_paths.rs +++ b/src/cargo/util/important_paths.rs @@ -1,16 +1,15 @@ -use std::os; +use std::env; use std::old_io::fs::PathExtensions; -use util::{CargoResult, CliError, CliResult, human}; +use util::{CargoResult, human, ChainError}; /// Iteratively search for `file` in `pwd` and its parents, returning /// the path of the directory. pub fn find_project(pwd: &Path, file: &str) -> CargoResult { - find_project_manifest(pwd, file) - .map(|mut p| { - // remove the file, leaving just the directory - p.pop(); - p - }) + find_project_manifest(pwd, file).map(|mut p| { + // remove the file, leaving just the directory + p.pop(); + p + }) } /// Iteratively search for `file` in `pwd` and its parents, returning @@ -32,16 +31,15 @@ pub fn find_project_manifest(pwd: &Path, file: &str) -> CargoResult { } /// Find the root Cargo.toml -pub fn find_root_manifest_for_cwd(manifest_path: Option) -> CliResult { - manifest_path.map(|path| Ok(Path::new(path))).unwrap_or_else(|| os::getcwd() - .map_err(|_| CliError::new("Couldn't determine the current working directory", 103)) - .and_then(|cwd| find_project_manifest(&cwd, "Cargo.toml") - .map_err(|_| CliError::new("Could not find Cargo.toml in this \ - directory or any parent directory", 102)) - ) - ) - .and_then(|path| os::make_absolute(&path).map_err(|_| - CliError::new("Could not determine the absolute path of the manifest", 104))) +pub fn find_root_manifest_for_cwd(manifest_path: Option) + -> CargoResult { + let cwd = try!(env::current_dir().chain_error(|| { + human("Couldn't determine the current working directory") + })); + match manifest_path { + Some(path) => Ok(cwd.join(path)), + None => find_project_manifest(&cwd, "Cargo.toml"), + } } /// Return the path to the `file` in `pwd`, if it exists. diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index 20525c4db..3284681c2 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -1,12 +1,15 @@ -use std::{old_io,os}; +use std::env; use std::old_io::fs; -use std::path::BytesContainer; +use std::old_io; +use std::old_path::BytesContainer; +use std::os; use util::{human, CargoResult}; pub fn realpath(original: &Path) -> old_io::IoResult { const MAX_LINKS_FOLLOWED: usize = 256; - let original = try!(os::make_absolute(original)); + let cwd = try!(env::current_dir()); + let original = cwd.join(original); // Right now lstat on windows doesn't work quite well if cfg!(windows) { @@ -41,6 +44,7 @@ pub fn realpath(original: &Path) -> old_io::IoResult { return Ok(result); } +#[allow(deprecated)] // need an OsStr-based Command first pub fn join_paths(paths: &[T], env: &str) -> CargoResult> { os::join_paths(paths).map_err(|e| { diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 28de7dfff..a29b3b902 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; +use std::env; use std::ffi::CString; use std::fmt::{self, Formatter}; use std::old_io::process::{Command, ProcessOutput, InheritFd}; -use std::os; -use std::path::BytesContainer; +use std::old_path::BytesContainer; use util::{CargoResult, ProcessError, process_error}; @@ -126,7 +126,7 @@ pub fn process(cmd: T) -> CargoResult { Ok(ProcessBuilder { program: CString::from_slice(cmd.container_as_bytes()), args: Vec::new(), - cwd: try!(os::getcwd()), + cwd: try!(env::current_dir()), env: HashMap::new(), }) } diff --git a/src/cargo/util/profile.rs b/src/cargo/util/profile.rs index c5aa87ed4..e17df6d22 100644 --- a/src/cargo/util/profile.rs +++ b/src/cargo/util/profile.rs @@ -1,6 +1,6 @@ -use std::os; -use std::mem; +use std::env; use std::fmt; +use std::mem; use time; use std::iter::repeat; use std::cell::RefCell; @@ -14,7 +14,7 @@ pub struct Profiler { desc: String, } -fn enabled() -> bool { os::getenv("CARGO_PROFILE").is_some() } +fn enabled() -> bool { env::var("CARGO_PROFILE").is_some() } pub fn start(desc: T) -> Profiler { if !enabled() { return Profiler { desc: String::new() } } diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index d86b75bb8..cab0a356a 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use std::fmt; use std::old_io::fs::{self, PathExtensions}; -use std::os; use std::slice; use std::str; use std::default::Default; @@ -95,7 +94,7 @@ pub fn to_manifest(contents: &[u8], config: &Config) -> CargoResult<(Manifest, Vec)> { let manifest = layout.root.join("Cargo.toml"); - let manifest = match manifest.path_relative_from(&try!(os::getcwd())) { + let manifest = match manifest.path_relative_from(config.cwd()) { Some(path) => path, None => manifest, }; diff --git a/src/rustversion.txt b/src/rustversion.txt index 54b77685e..0d845a26a 100644 --- a/src/rustversion.txt +++ b/src/rustversion.txt @@ -1 +1 @@ -2015-02-03 +2015-02-05 diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 4fe302caf..83be2957b 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -1,10 +1,10 @@ use std::error::Error; +use std::env; use std::fmt; use std::old_io::fs::{self, PathExtensions}; use std::old_io::process::{ProcessOutput}; use std::old_io; -use std::os; -use std::path::{Path, BytesContainer}; +use std::old_path::{Path, BytesContainer}; use std::str::{self, Str}; use url::Url; @@ -102,16 +102,17 @@ impl ProjectBuilder { pub fn url(&self) -> Url { path2url(self.root()) } pub fn bin(&self, b: &str) -> Path { - self.build_dir().join(format!("{}{}", b, os::consts::EXE_SUFFIX)) + self.build_dir().join(format!("{}{}", b, env::consts::EXE_SUFFIX)) } pub fn release_bin(&self, b: &str) -> Path { - self.build_dir().join("release").join(format!("{}{}", b, os::consts::EXE_SUFFIX)) + self.build_dir().join("release").join(format!("{}{}", b, + env::consts::EXE_SUFFIX)) } pub fn target_bin(&self, target: &str, b: &str) -> Path { self.build_dir().join(target).join(format!("{}{}", b, - os::consts::EXE_SUFFIX)) + env::consts::EXE_SUFFIX)) } pub fn build_dir(&self) -> Path { @@ -226,8 +227,8 @@ impl ErrMsg for Result { // Path to cargo executables pub fn cargo_dir() -> Path { - os::getenv("CARGO_BIN_PATH").map(Path::new) - .or_else(|| os::self_exe_path()) + env::var_string("CARGO_BIN_PATH").map(Path::new).ok() + .or_else(|| env::current_exe().ok().map(|s| s.dir_path())) .unwrap_or_else(|| { panic!("CARGO_BIN_PATH wasn't set. Cannot continue running test") }) diff --git a/tests/support/paths.rs b/tests/support/paths.rs index cbecafcf6..1a2d63764 100644 --- a/tests/support/paths.rs +++ b/tests/support/paths.rs @@ -1,7 +1,8 @@ use std::old_io::IoResult; +use std::env; use std::old_io::fs::{self, PathExtensions}; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; -use std::{old_io, os}; +use std::old_io; use cargo::util::realpath; @@ -10,7 +11,8 @@ static NEXT_ID: AtomicUsize = ATOMIC_USIZE_INIT; thread_local!(static TASK_ID: usize = NEXT_ID.fetch_add(1, Ordering::SeqCst)); pub fn root() -> Path { - let path = os::self_exe_path().unwrap() + let path = env::current_exe().unwrap() + .dir_path() .join(CARGO_INTEGRATION_TEST_DIR) .join(TASK_ID.with(|my_id| format!("test-{}", my_id))); realpath(&path).unwrap() diff --git a/tests/test_cargo.rs b/tests/test_cargo.rs index 2eda962b4..b4b1abd14 100644 --- a/tests/test_cargo.rs +++ b/tests/test_cargo.rs @@ -1,7 +1,8 @@ +use std::env; +use std::ffi::OsString; use std::old_io::fs; -use std::old_io; use std::old_io::{USER_RWX, File}; -use std::os; +use std::old_io; use std::str; use cargo::util::process; @@ -15,7 +16,7 @@ fn setup() { /// Add an empty file with executable flags (and platform-dependent suffix). /// TODO: move this to `ProjectBuilder` if other cases using this emerge. fn fake_executable(proj: ProjectBuilder, dir: &Path, name: &str) -> ProjectBuilder { - let path = proj.root().join(dir).join(format!("{}{}", name, os::consts::EXE_SUFFIX)); + let path = proj.root().join(dir).join(format!("{}{}", name, env::consts::EXE_SUFFIX)); mkdir_recursive(&Path::new(path.dirname())).unwrap(); fs::File::create(&path).unwrap(); let old_io::FileStat{perm, ..} = fs::stat(&path).unwrap(); @@ -24,9 +25,9 @@ fn fake_executable(proj: ProjectBuilder, dir: &Path, name: &str) -> ProjectBuild } fn path() -> Vec { - let path = os::getenv_as_bytes("PATH").unwrap_or(Vec::new()); - os::split_paths(path) + env::split_paths(&env::var("PATH").unwrap_or(OsString::new())).collect() } + test!(list_commands_looks_at_path { let proj = project("list-non-overlapping"); let proj = fake_executable(proj, &Path::new("path-test"), "cargo-1"); @@ -37,8 +38,9 @@ test!(list_commands_looks_at_path { let mut path = path(); path.push(proj.root().join("path-test")); - let path = os::join_paths(path.as_slice()).unwrap(); - let output = pr.arg("-v").arg("--list").env("PATH", Some(path.as_slice())); + let path = env::join_paths(path.iter()).unwrap(); + let output = pr.arg("-v").arg("--list") + .env("PATH", Some(path.to_str().unwrap())); let output = output.exec_with_output().unwrap(); let output = str::from_utf8(output.output.as_slice()).unwrap(); assert!(output.contains("\n 1\n"), "missing 1: {}", output); diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index 9d472b7f7..7237a71d3 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -1,4 +1,4 @@ -use std::path; +use std::old_path; use std::str; use support::{project, execs, basic_bin_manifest, basic_lib_manifest}; @@ -186,7 +186,7 @@ thread '
' panicked at 'assertion failed: \ `(left == right) && (right == left)` (left: \ `\"hello\"`, right: `\"nope\"`)', src{sep}foo.rs:14 -", sep = path::SEP)) +", sep = old_path::SEP)) .with_status(101)); }); @@ -865,5 +865,5 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured running = RUNNING, dir = p.root().display(), url = p.url(), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); }); diff --git a/tests/test_cargo_build_lib.rs b/tests/test_cargo_build_lib.rs index 6b6064a3a..ee0842b33 100644 --- a/tests/test_cargo_build_lib.rs +++ b/tests/test_cargo_build_lib.rs @@ -1,4 +1,4 @@ -use std::path; +use std::old_path; use support::{basic_bin_manifest, execs, project, ProjectBuilder}; use support::{COMPILING, RUNNING}; use hamcrest::{assert_that}; @@ -17,7 +17,7 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String { -L dependency={dir}{sep}target \ -L dependency={dir}{sep}target{sep}deps` ", - running = RUNNING, compiling = COMPILING, sep = path::SEP, + running = RUNNING, compiling = COMPILING, sep = old_path::SEP, dir = p.root().display(), url = p.url(), name = "foo", version = "0.0.1") } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 886c7dfc1..6fd759f69 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1,6 +1,6 @@ use std::old_io::{self, fs, TempDir, File}; -use std::os; -use std::path; +use std::env; +use std::old_path; use support::{project, execs, main_file, basic_bin_manifest}; use support::{COMPILING, RUNNING, cargo_dir, ProjectBuilder}; @@ -119,10 +119,10 @@ test!(cargo_compile_without_manifest { let p = ProjectBuilder::new("foo", tmpdir.path().clone()); assert_that(p.cargo_process("build"), - execs() - .with_status(102) - .with_stderr("Could not find Cargo.toml in this directory or any \ - parent directory\n")); + execs().with_status(101) + .with_stderr("\ +Could not find `Cargo.toml` in `[..]` or any parent directory +")); }); test!(cargo_compile_with_invalid_code { @@ -140,7 +140,7 @@ test!(cargo_compile_with_invalid_code { Could not compile `foo`. To learn more, run the command again with --verbose.\n", - filename = format!("src{}foo.rs", path::SEP)).as_slice())); + filename = format!("src{}foo.rs", old_path::SEP)).as_slice())); assert_that(&p.root().join("Cargo.lock"), existing_file()); }); @@ -181,7 +181,7 @@ test!(cargo_compile_with_warnings_in_the_root_package { on by default {filename}:1 fn main() {{}} fn dead() {{}} ^~~~~~~~~~~~ -", filename = format!("src{}foo.rs", path::SEP).as_slice()))); +", filename = format!("src{}foo.rs", old_path::SEP).as_slice()))); }); test!(cargo_compile_with_warnings_in_a_dep_package { @@ -648,8 +648,8 @@ test!(many_crate_types_old_style_lib_location { let file1 = files[1].as_slice(); println!("{} {}", file0, file1); assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib")); - assert!(file0.ends_with(os::consts::DLL_SUFFIX) || - file1.ends_with(os::consts::DLL_SUFFIX)); + assert!(file0.ends_with(env::consts::DLL_SUFFIX) || + file1.ends_with(env::consts::DLL_SUFFIX)); }); test!(many_crate_types_correct { @@ -686,8 +686,8 @@ test!(many_crate_types_correct { let file1 = files[1].as_slice(); println!("{} {}", file0, file1); assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib")); - assert!(file0.ends_with(os::consts::DLL_SUFFIX) || - file1.ends_with(os::consts::DLL_SUFFIX)); + assert!(file0.ends_with(env::consts::DLL_SUFFIX) || + file1.ends_with(env::consts::DLL_SUFFIX)); }); test!(unused_keys { @@ -822,7 +822,7 @@ test!(lto_build { -L dependency={dir}{sep}target{sep}release \ -L dependency={dir}{sep}target{sep}release{sep}deps` ", -running = RUNNING, compiling = COMPILING, sep = path::SEP, +running = RUNNING, compiling = COMPILING, sep = old_path::SEP, dir = p.root().display(), url = p.url(), ))); @@ -850,7 +850,7 @@ test!(verbose_build { -L dependency={dir}{sep}target \ -L dependency={dir}{sep}target{sep}deps` ", -running = RUNNING, compiling = COMPILING, sep = path::SEP, +running = RUNNING, compiling = COMPILING, sep = old_path::SEP, dir = p.root().display(), url = p.url(), ))); @@ -880,7 +880,7 @@ test!(verbose_release_build { -L dependency={dir}{sep}target{sep}release \ -L dependency={dir}{sep}target{sep}release{sep}deps` ", -running = RUNNING, compiling = COMPILING, sep = path::SEP, +running = RUNNING, compiling = COMPILING, sep = old_path::SEP, dir = p.root().display(), url = p.url(), ))); @@ -943,9 +943,9 @@ test!(verbose_release_build_deps { compiling = COMPILING, dir = p.root().display(), url = p.url(), - sep = path::SEP, - prefix = os::consts::DLL_PREFIX, - suffix = os::consts::DLL_SUFFIX).as_slice())); + sep = old_path::SEP, + prefix = env::consts::DLL_PREFIX, + suffix = env::consts::DLL_SUFFIX).as_slice())); }); test!(explicit_examples { @@ -1293,12 +1293,12 @@ test!(rebuild_preserves_out_dir { build = 'build.rs' "#) .file("build.rs", r#" - use std::os; + use std::env; use std::old_io::File; fn main() { - let path = Path::new(os::getenv("OUT_DIR").unwrap()).join("foo"); - if os::getenv("FIRST").is_some() { + let path = Path::new(env::var_string("OUT_DIR").unwrap()).join("foo"); + if env::var("FIRST").is_some() { File::create(&path).unwrap(); } else { File::create(&path).unwrap(); diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index bf80eebaf..038ec33f5 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -1,5 +1,5 @@ +use std::env; use std::old_io::{File, fs}; -use std::os; use support::{project, execs, cargo_dir}; use support::{COMPILING, RUNNING, DOCTEST}; @@ -23,9 +23,9 @@ test!(custom_build_script_failed { fn main() {} "#) .file("build.rs", r#" - #![feature(os)] + #![feature(env)] fn main() { - std::os::set_exit_status(101); + std::env::set_exit_status(101); } "#); assert_that(p.cargo_process("build").arg("-v"), @@ -76,34 +76,35 @@ test!(custom_build_env_vars { "#); let file_content = format!(r#" - use std::os; + use std::env; use std::old_io::fs::PathExtensions; fn main() {{ - let _target = os::getenv("TARGET").unwrap(); + let _target = env::var_string("TARGET").unwrap(); - let _ncpus = os::getenv("NUM_JOBS").unwrap(); + let _ncpus = env::var_string("NUM_JOBS").unwrap(); - let out = os::getenv("CARGO_MANIFEST_DIR").unwrap(); + let out = env::var_string("CARGO_MANIFEST_DIR").unwrap(); let p1 = Path::new(out); - let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path()).unwrap(); + let cwd = env::current_dir().unwrap(); + let p2 = cwd.join(Path::new(file!()).dir_path().dir_path()); assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display()); - let opt = os::getenv("OPT_LEVEL").unwrap(); + let opt = env::var_string("OPT_LEVEL").unwrap(); assert_eq!(opt.as_slice(), "0"); - let opt = os::getenv("PROFILE").unwrap(); + let opt = env::var_string("PROFILE").unwrap(); assert_eq!(opt.as_slice(), "compile"); - let debug = os::getenv("DEBUG").unwrap(); + let debug = env::var_string("DEBUG").unwrap(); assert_eq!(debug.as_slice(), "true"); - let out = os::getenv("OUT_DIR").unwrap(); + let out = env::var_string("OUT_DIR").unwrap(); assert!(out.as_slice().starts_with(r"{0}")); assert!(Path::new(out).is_dir()); - let _host = os::getenv("HOST").unwrap(); + let _host = env::var_string("HOST").unwrap(); - let _feat = os::getenv("CARGO_FEATURE_FOO").unwrap(); + let _feat = env::var_string("CARGO_FEATURE_FOO").unwrap(); }} "#, p.root().join("target").join("build").display()); @@ -266,10 +267,10 @@ test!(overrides_and_links { "#) .file("src/lib.rs", "") .file("build.rs", r#" - use std::os; + use std::env; fn main() { - assert_eq!(os::getenv("DEP_FOO_FOO").unwrap().as_slice(), "bar"); - assert_eq!(os::getenv("DEP_FOO_BAR").unwrap().as_slice(), "baz"); + assert_eq!(env::var_string("DEP_FOO_FOO").unwrap().as_slice(), "bar"); + assert_eq!(env::var_string("DEP_FOO_BAR").unwrap().as_slice(), "baz"); } "#) .file(".cargo/config", format!(r#" @@ -339,10 +340,10 @@ test!(links_passes_env_vars { "#) .file("src/lib.rs", "") .file("build.rs", r#" - use std::os; + use std::env; fn main() { - assert_eq!(os::getenv("DEP_FOO_FOO").unwrap().as_slice(), "bar"); - assert_eq!(os::getenv("DEP_FOO_BAR").unwrap().as_slice(), "baz"); + assert_eq!(env::var_string("DEP_FOO_FOO").unwrap().as_slice(), "bar"); + assert_eq!(env::var_string("DEP_FOO_BAR").unwrap().as_slice(), "baz"); } "#) .file("a/Cargo.toml", r#" @@ -438,10 +439,10 @@ test!(rebuild_continues_to_pass_env_vars { "#, a.root().display())) .file("src/lib.rs", "") .file("build.rs", r#" - use std::os; + use std::env; fn main() { - assert_eq!(os::getenv("DEP_FOO_FOO").unwrap().as_slice(), "bar"); - assert_eq!(os::getenv("DEP_FOO_BAR").unwrap().as_slice(), "baz"); + assert_eq!(env::var_string("DEP_FOO_FOO").unwrap().as_slice(), "bar"); + assert_eq!(env::var_string("DEP_FOO_BAR").unwrap().as_slice(), "baz"); } "#); @@ -723,10 +724,10 @@ test!(out_dir_is_preserved { "#) .file("src/lib.rs", "") .file("build.rs", r#" - use std::os; + use std::env; use std::old_io::File; fn main() { - let out = os::getenv("OUT_DIR").unwrap(); + let out = env::var_string("OUT_DIR").unwrap(); File::create(&Path::new(out).join("foo")).unwrap(); } "#); @@ -738,10 +739,10 @@ test!(out_dir_is_preserved { // Change to asserting that it's there File::create(&p.root().join("build.rs")).write_str(r#" - use std::os; + use std::env; use std::old_io::File; fn main() { - let out = os::getenv("OUT_DIR").unwrap(); + let out = env::var_string("OUT_DIR").unwrap(); File::open(&Path::new(out).join("foo")).unwrap(); } "#).unwrap(); @@ -803,11 +804,11 @@ test!(code_generation { } "#) .file("build.rs", r#" - use std::os; + use std::env; use std::old_io::File; fn main() { - let dst = Path::new(os::getenv("OUT_DIR").unwrap()); + let dst = Path::new(env::var_string("OUT_DIR").unwrap()); let mut f = File::create(&dst.join("hello.rs")).unwrap(); f.write_str(" pub fn message() -> &'static str { @@ -967,11 +968,11 @@ test!(test_a_lib_with_a_build_command { } "#) .file("build.rs", r#" - use std::os; + use std::env; use std::old_io::File; fn main() { - let out = Path::new(os::getenv("OUT_DIR").unwrap()); + let out = Path::new(env::var_string("OUT_DIR").unwrap()); File::create(&out.join("foo.rs")).write_str(" fn foo() -> int { 1 } ").unwrap(); @@ -1027,12 +1028,12 @@ test!(build_script_with_dynamic_native_dependency { let src = build.root().join("target"); let lib = fs::readdir(&src).unwrap().into_iter().find(|lib| { let lib = lib.filename_str().unwrap(); - lib.starts_with(os::consts::DLL_PREFIX) && - lib.ends_with(os::consts::DLL_SUFFIX) + lib.starts_with(env::consts::DLL_PREFIX) && + lib.ends_with(env::consts::DLL_SUFFIX) }).unwrap(); let libname = lib.filename_str().unwrap(); - let libname = &libname[os::consts::DLL_PREFIX.len().. - libname.len() - os::consts::DLL_SUFFIX.len()]; + let libname = &libname[env::consts::DLL_PREFIX.len().. + libname.len() - env::consts::DLL_SUFFIX.len()]; let foo = project("foo") .file("Cargo.toml", r#" @@ -1058,10 +1059,10 @@ test!(build_script_with_dynamic_native_dependency { build = "build.rs" "#) .file("bar/build.rs", r#" - use std::os; + use std::env; fn main() { - let src = Path::new(os::getenv("SRC").unwrap()); + let src = Path::new(env::var_string("SRC").unwrap()); println!("cargo:rustc-flags=-L {}", src.dir_path().display()); } "#) diff --git a/tests/test_cargo_compile_plugins.rs b/tests/test_cargo_compile_plugins.rs index e375e3727..853038ff3 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/test_cargo_compile_plugins.rs @@ -1,5 +1,5 @@ use std::old_io::fs; -use std::os; +use std::env; use support::{project, execs, cargo_dir}; use hamcrest::assert_that; @@ -103,12 +103,12 @@ test!(plugin_with_dynamic_native_dependency { let src = build.root().join("target"); let lib = fs::readdir(&src).unwrap().into_iter().find(|lib| { let lib = lib.filename_str().unwrap(); - lib.starts_with(os::consts::DLL_PREFIX) && - lib.ends_with(os::consts::DLL_SUFFIX) + lib.starts_with(env::consts::DLL_PREFIX) && + lib.ends_with(env::consts::DLL_SUFFIX) }).unwrap(); let libname = lib.filename_str().unwrap(); - let libname = &libname[os::consts::DLL_PREFIX.len().. - libname.len() - os::consts::DLL_SUFFIX.len()]; + let libname = &libname[env::consts::DLL_PREFIX.len().. + libname.len() - env::consts::DLL_SUFFIX.len()]; let foo = project("foo") .file("Cargo.toml", r#" diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index ccd79bc53..a2d53e0bb 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -1,5 +1,5 @@ -use std::os; -use std::path; +use std::env; +use std::old_path; use support::{project, execs, basic_bin_manifest}; use support::{RUNNING, COMPILING, DOCTEST, cargo_dir}; @@ -12,8 +12,8 @@ fn setup() { fn disabled() -> bool { // First, disable if ./configure requested so - match os::getenv("CFG_DISABLE_CROSS_TESTS") { - Some(ref s) if s.as_slice() == "1" => return true, + match env::var_string("CFG_DISABLE_CROSS_TESTS") { + Ok(ref s) if s.as_slice() == "1" => return true, _ => {} } @@ -24,7 +24,7 @@ fn disabled() -> bool { } fn alternate() -> &'static str { - match os::consts::SYSNAME { + match env::consts::OS { "linux" => "i686-unknown-linux-gnu", "macos" => "i686-apple-darwin", _ => unreachable!(), @@ -44,13 +44,13 @@ test!(simple_cross { "#) .file("build.rs", format!(r#" fn main() {{ - assert_eq!(std::os::getenv("TARGET").unwrap().as_slice(), "{}"); + assert_eq!(std::env::var_string("TARGET").unwrap().as_slice(), "{}"); }} "#, alternate()).as_slice()) .file("src/main.rs", r#" - use std::os; + use std::env; fn main() { - assert_eq!(os::consts::ARCH, "x86"); + assert_eq!(env::consts::ARCH, "x86"); } "#); @@ -277,9 +277,9 @@ test!(linker_and_ar { "#, target).as_slice()) .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) .file("src/foo.rs", r#" - use std::os; + use std::env; fn main() { - assert_eq!(os::consts::ARCH, "x86"); + assert_eq!(env::consts::ARCH, "x86"); } "#); @@ -301,7 +301,7 @@ test!(linker_and_ar { dir = p.root().display(), url = p.url(), target = target, - sep = path::SEP, + sep = old_path::SEP, ).as_slice())); }); @@ -386,15 +386,15 @@ test!(cross_tests { "#) .file("src/main.rs", r#" extern crate foo; - use std::os; + use std::env; fn main() { - assert_eq!(os::consts::ARCH, "x86"); + assert_eq!(env::consts::ARCH, "x86"); } #[test] fn test() { main() } "#) .file("src/lib.rs", r#" - use std::os; - pub fn foo() { assert_eq!(os::consts::ARCH, "x86"); } + use std::env; + pub fn foo() { assert_eq!(env::consts::ARCH, "x86"); } #[test] fn test_foo() { foo() } "#); @@ -438,9 +438,9 @@ test!(simple_cargo_run { authors = [] "#) .file("src/main.rs", r#" - use std::os; + use std::env; fn main() { - assert_eq!(os::consts::ARCH, "x86"); + assert_eq!(env::consts::ARCH, "x86"); } "#); @@ -462,10 +462,10 @@ test!(cross_with_a_build_script { build = 'build.rs' "#) .file("build.rs", format!(r#" - use std::os; + use std::env; fn main() {{ - assert_eq!(os::getenv("TARGET").unwrap().as_slice(), "{0}"); - let mut path = Path::new(os::getenv("OUT_DIR").unwrap()); + assert_eq!(env::var_string("TARGET").unwrap().as_slice(), "{0}"); + let mut path = Path::new(env::var_string("OUT_DIR").unwrap()); assert_eq!(path.filename().unwrap(), b"out"); path.pop(); assert!(path.filename().unwrap().starts_with(b"foo-")); @@ -487,7 +487,7 @@ test!(cross_with_a_build_script { {running} `{dir}{sep}target{sep}build{sep}foo-[..]build-script-build` {running} `rustc src{sep}main.rs [..] --target {target} [..]` ", compiling = COMPILING, running = RUNNING, target = target, - dir = p.root().display(), sep = path::SEP).as_slice())); + dir = p.root().display(), sep = old_path::SEP).as_slice())); }); test!(build_script_needed_for_host_and_target { @@ -528,9 +528,9 @@ test!(build_script_needed_for_host_and_target { pub fn d1() {} ") .file("d1/build.rs", r#" - use std::os; + use std::env; fn main() { - let target = os::getenv("TARGET").unwrap(); + let target = env::var_string("TARGET").unwrap(); println!("cargo:rustc-flags=-L /path/to/{}", target); } "#) @@ -569,7 +569,7 @@ test!(build_script_needed_for_host_and_target { {running} `rustc src{sep}main.rs [..] --target {target} [..] \ -L /path/to/{target}` ", compiling = COMPILING, running = RUNNING, target = target, host = host, - dir = p.root().display(), sep = path::SEP).as_slice())); + dir = p.root().display(), sep = old_path::SEP).as_slice())); }); test!(build_deps_for_the_right_arch { @@ -640,12 +640,12 @@ test!(build_script_only_host { pub fn d1() {} ") .file("d1/build.rs", r#" - use std::os; + use std::env; fn main() { - assert!(os::getenv("OUT_DIR").unwrap() + assert!(env::var_string("OUT_DIR").unwrap() .contains("target/build/d1-"), - "bad: {:?}", os::getenv("OUT_DIR")); + "bad: {:?}", env::var_string("OUT_DIR")); } "#); diff --git a/tests/test_cargo_new.rs b/tests/test_cargo_new.rs index b78d42c8c..3dfdfea55 100644 --- a/tests/test_cargo_new.rs +++ b/tests/test_cargo_new.rs @@ -1,6 +1,6 @@ use std::old_io::{fs, USER_RWX, File, TempDir}; use std::old_io::fs::PathExtensions; -use std::os; +use std::env; use support::{execs, paths, cargo_dir}; use hamcrest::{assert_that, existing_file, existing_dir, is_not}; @@ -23,8 +23,8 @@ fn cargo_process(s: &str) -> ProcessBuilder { } test!(simple_lib { - os::setenv("USER", "foo"); - assert_that(cargo_process("new").arg("foo").arg("--vcs").arg("none"), + assert_that(cargo_process("new").arg("foo").arg("--vcs").arg("none") + .env("USER", Some("foo")), execs().with_status(0)); assert_that(&paths::root().join("foo"), existing_dir()); @@ -37,8 +37,8 @@ test!(simple_lib { }); test!(simple_bin { - os::setenv("USER", "foo"); - assert_that(cargo_process("new").arg("foo").arg("--bin"), + assert_that(cargo_process("new").arg("foo").arg("--bin") + .env("USER", Some("foo")), execs().with_status(0)); assert_that(&paths::root().join("foo"), existing_dir()); @@ -48,14 +48,14 @@ test!(simple_bin { assert_that(cargo_process("build").cwd(paths::root().join("foo")), execs().with_status(0)); assert_that(&paths::root().join(format!("foo/target/foo{}", - os::consts::EXE_SUFFIX)), + env::consts::EXE_SUFFIX)), existing_file()); }); test!(simple_git { let td = TempDir::new("cargo").unwrap(); - os::setenv("USER", "foo"); - assert_that(cargo_process("new").arg("foo").cwd(td.path().clone()), + assert_that(cargo_process("new").arg("foo").cwd(td.path().clone()) + .env("USER", Some("foo")), execs().with_status(0)); assert_that(td.path(), existing_dir()); @@ -175,8 +175,8 @@ test!(git_prefers_command_line { }); test!(subpackage_no_git { - os::setenv("USER", "foo"); - assert_that(cargo_process("new").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("new").arg("foo").env("USER", Some("foo")), + execs().with_status(0)); let subpackage = paths::root().join("foo").join("components"); fs::mkdir(&subpackage, USER_RWX).unwrap(); diff --git a/tests/test_cargo_profiles.rs b/tests/test_cargo_profiles.rs index e4f0cd67c..b71eadb34 100644 --- a/tests/test_cargo_profiles.rs +++ b/tests/test_cargo_profiles.rs @@ -1,5 +1,5 @@ use std::os; -use std::path; +use std::old_path; use support::{project, execs}; use support::{COMPILING, RUNNING}; @@ -38,7 +38,7 @@ test!(profile_overrides { -L dependency={dir}{sep}target \ -L dependency={dir}{sep}target{sep}deps` ", -running = RUNNING, compiling = COMPILING, sep = path::SEP, +running = RUNNING, compiling = COMPILING, sep = old_path::SEP, dir = p.root().display(), url = p.url(), ))); @@ -109,7 +109,7 @@ test!(top_level_overrides_deps { compiling = COMPILING, dir = p.root().display(), url = p.url(), - sep = path::SEP, + sep = old_path::SEP, prefix = os::consts::DLL_PREFIX, suffix = os::consts::DLL_SUFFIX).as_slice())); }); diff --git a/tests/test_cargo_run.rs b/tests/test_cargo_run.rs index f8077f395..1abd19dc1 100644 --- a/tests/test_cargo_run.rs +++ b/tests/test_cargo_run.rs @@ -1,4 +1,4 @@ -use std::path; +use std::old_path; use support::{project, cargo_dir, execs, path2url}; use support::{COMPILING, RUNNING}; @@ -28,7 +28,7 @@ hello compiling = COMPILING, running = RUNNING, dir = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); assert_that(&p.bin("foo"), existing_file()); }); @@ -129,7 +129,7 @@ hello a.rs compiling = COMPILING, running = RUNNING, dir = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); assert_that(p.process(cargo_dir().join("cargo")).arg("run").arg("--bin").arg("b"), execs().with_status(0).with_stdout(format!("\ @@ -137,7 +137,7 @@ hello a.rs hello b.rs ", running = RUNNING, - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); }); test!(run_example { @@ -165,7 +165,7 @@ example compiling = COMPILING, running = RUNNING, dir = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); }); test!(either_name_or_example { @@ -217,7 +217,7 @@ hello main.rs compiling = COMPILING, running = RUNNING, dir = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); }); test!(example_with_release_flag { @@ -292,7 +292,7 @@ fast2 running = RUNNING, dir = p.root().display(), url = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); assert_that(p.process(cargo_dir().join("cargo")).arg("run").arg("-v").arg("--example").arg("a"), execs().with_status(0).with_stdout(format!("\ @@ -321,7 +321,7 @@ slow2 running = RUNNING, dir = p.root().display(), url = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); }); test!(run_dylib_dep { @@ -375,7 +375,7 @@ test!(release_works { compiling = COMPILING, running = RUNNING, dir = path2url(p.root()), - sep = path::SEP).as_slice())); + sep = old_path::SEP).as_slice())); assert_that(&p.release_bin("foo"), existing_file()); }); diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index e9279d8eb..21b690864 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1,4 +1,4 @@ -use std::path; +use std::old_path; use std::str; use support::{project, execs, basic_bin_manifest, basic_lib_manifest}; @@ -148,7 +148,7 @@ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured ", COMPILING, p.url(), RUNNING, - sep = path::SEP)) + sep = old_path::SEP)) .with_stderr(format!("\ thread '
' panicked at 'Some tests failed', [..] diff --git a/tests/tests.rs b/tests/tests.rs index c2a4f6780..1ab15c83e 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,5 +1,5 @@ #![deny(warnings)] -#![feature(collections, core, io, os, path, rustc_private, std_misc)] +#![feature(collections, core, io, os, path, rustc_private, std_misc, env)] extern crate cargo; extern crate flate2; -- 2.30.2